package yxy.cherry.battle.module.affix.buff;

import yxy.cherry.battle.Battle;
import yxy.cherry.battle.Fighter;
import yxy.cherry.battle.module.PropertyData;
import yxy.cherry.battle.module.PropertyType;
import yxy.cherry.battle.module.affix.AffixFactory;
import yxy.cherry.battle.module.affix.Buff;
import yxy.cherry.battle.module.affix.BuffType;
import yxy.cherry.battle.module.record.stream.RecordStream34LossHpAddAttribute;
import yxy.cherry.data.bean.skill;

/**
 * @author James
 * 属性加靠失血（不屈）每损失X%的最大生命值，增加X%的X属性；
 * @date 2022/3/12 12:23
 */
@BuffType(Type = AffixFactory.BuffTypeEnum.属性加靠失血)
public class Affix77AddAttributePerByLossHp extends Buff {


    public Affix77AddAttributePerByLossHp(Fighter source, Fighter target, skill skilldata, int[] params) {
        super(source, target, skilldata, params);
    }

    private int getReducePer() {return getParam(0);}
    private int getAttribute() {return getParam(1);}
    private int getAddPer() {return getParam(2);}
    @Override
    public boolean exec(Fighter source, Fighter target) {
        long lossHpPer = VALUE_比率分母 - target.get血量万分值();
        int times = (int) (lossHpPer / getReducePer());

        PropertyData propertyData = new PropertyData();
        long addValue = target.getData().getPropertyData().getValue(PropertyType.forNumber(getAttribute())) * times * getAddPer()/VALUE_比率分母;
        propertyData.setValue(PropertyType.forNumber(getAttribute()),addValue);
        setPropertyData(propertyData);
        getRecord().stream(new RecordStream34LossHpAddAttribute(target, getAttribute(), addValue,this)).record();
        Battle.battleLogger(6,"属性加靠失血：施法者"+source.getName()+"目标："+target.getName()+"损失血量万分值："+lossHpPer+"基础值："+getReducePer()+"属性："+getAttribute()+"属性值："+target.getData().getPropertyData().getValue(PropertyType.forNumber(getAttribute()))+"增加值："+addValue);
        return true;
    }

    @Override
    public BuffType getBuffType() {
        return BuffType.属性加效果;
    }

    @Override
    public BuffStateType getBuffStateType() {
        return BuffStateType.属性加状态;
    }
}
